Xbasic

GET_UNIQUE_FILENAME Function

Syntax

Filename as C = get_unique_filename(C root_filename [,C prefix [,C extension [,N mode [,C number_prefix ]]]])

Arguments

Filename

A unique path-filename combination.

root_filename

If Root_Filename is blank, then Alpha Anywhere will create a unique filename in the user's Temporary folder. Otherwise, Alpha Anywhere will return a unique filename in the same folder as the Root_Filename . For example, if the Root_Filename is c:\file.txt, and if this file exists, the function will return c:\file1.txt (assuming that this file does not already exist).

prefix

Optional. Ignored if Root_Filename is not blank. Prefix of the filename that is returned.

extension

Optional. Ignored if Root_Filename is not blank. Extension of the filename that is returned.

mode

Numeric

number_prefix

Character

Description

Takes a root filename and increments a trailing digit in the name until the root filename is unique. If root_filename is blank, returns a unique filename with the specified prefix and extension in the temp folder. If mode = 1 then the trailing digit (if any) on the filename that was past in will be incremented. 'number_prefix' is inserted infront of the number that is used to increment the filename.

The GET_UNIQUE_FILENAME() function generates a unique filename by incrementing a trailing digit in the filename.

Example

? get_unique_filename("", "", ".txt") 
 = "C:\DOCUME~1\SELWYN~1.ALP\LOCALS~1\Temp\irtoxpxv.txt>"

'In this case, the generated filename starts with 'test_'  and has a '.txt' extension 
? get_unique_filename("", "test_", ".txt") 
 = "C:\DOCUME~1\SELWYN~1.ALP\LOCALS~1\Temp\test_kgh.txt"

'In this case the 'customer.dbf' file already exists: 
? get_unique_filename("c:\program files\a5v6\samples\alphasports\customer.dbf",  "", ".txt") 
= "c:\program files\a5v6\samples\alphasports\customer1.dbf"

See Also